import * as actionTypes from './constants';
import * as api from './api'

const defaultstate = {
    shopcarData: [],
    allMoney:0,
    iSAllSelected:false,
    totalnum:2
}

const reducer = (state = defaultstate, action) => {
    switch (action.type) {
        case actionTypes.CHANGE_SHOPCARDATA:       
            return {...state,shopcarData:action.data}    
        case actionTypes.DELETE:
            return {...state, shopcarData: api.deleteItem(action.data,state.shopcarData),totalnum:api.totalnum(state.shopcarData), allMoney:api.allmoney(state.shopcarData), iSAllSelected:api.allSelected(state.shopcarData)}  
        case actionTypes.GOTOSHOPCAR:
            return {...state, shopcarData: api.goToShopCar_btn(action.data,state.shopcarData),totalnum:api.totalnum(state.shopcarData)}  
        case actionTypes.CHANGE_LOGO:
            return {...state, shopcarData: api.change_logo(action.data,state.shopcarData),
            allMoney:api.allmoney(state.shopcarData),
            iSAllSelected:api.allSelected(state.shopcarData)
            }
        case actionTypes.LESSEN_NUM:
            return {...state, shopcarData: api.less_num(action.data,state.shopcarData),allMoney:api.allmoney(state.shopcarData), iSAllSelected:api.allSelected(state.shopcarData),totalnum:api.totalnum(state.shopcarData)} 
        case actionTypes.ADD_NUM:
            return {...state, shopcarData: api.add_num(action.data,state.shopcarData),allMoney:api.allmoney(state.shopcarData), iSAllSelected:api.allSelected(state.shopcarData),totalnum:api.totalnum(state.shopcarData)} 
        case actionTypes.CHNANGE_NUM:
            return {...state, shopcarData: api.change_num(action.data,state.shopcarData),allMoney:api.allmoney(state.shopcarData), iSAllSelected:api.allSelected(state.shopcarData),totalnum:api.totalnum(state.shopcarData)} 
        case actionTypes.SELECT_ALL:
            return {...state, shopcarData: api.SelectedAll(state.shopcarData),
                allMoney:api.allmoney(state.shopcarData), iSAllSelected:api.allSelected(state.shopcarData)
            } 
        default:
            return state;
    }
}
export default reducer;